package com.markby.fscm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.markby.fscm.common.ResultCodeEnum;
import com.markby.fscm.common.exception.SSCMException;
import com.markby.fscm.domain.AdminSettings;
import com.markby.fscm.domain.RecordLogEnum;
import com.markby.fscm.service.AdminSettingsService;
import com.markby.fscm.mapper.AdminSettingsMapper;
import com.markby.fscm.service.RecordLogService;
import com.markby.fscm.utils.PasswordUtils;
import com.markby.fscm.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author baoyu
 * @description 针对表【admin_settings】的数据库操作Service实现
 * @createDate 2024-08-11 08:29:59
 */
@Service
public class AdminSettingsServiceImpl extends ServiceImpl<AdminSettingsMapper, AdminSettings>
        implements AdminSettingsService {

    @Autowired
    private RecordLogService recordLogService;

    @Override
    public void verifyPassword(String password, String source) {

        if (StringUtils.isBlank(password)) {
            recordLogService.record(RecordLogEnum.PASSWORD_VERIFY_FAIL, source);
            throw new SSCMException(ResultCodeEnum.ADMIN_ACCOUNT_ERROR);
        }
        String hashedPassword = baseMapper.getPassword();

        if (!PasswordUtils.verifyPassword(password, hashedPassword)) {
            recordLogService.record(RecordLogEnum.PASSWORD_VERIFY_FAIL, source);
            throw new SSCMException(ResultCodeEnum.ADMIN_ACCOUNT_ERROR);
        }
        recordLogService.record(RecordLogEnum.LOGIN_SUCCESS, source);

    }
}




